<template>
	<view class="wrap">
		<js-error mode="bottom" ref="jsError"></js-error>
		<view class="search">
			<u-search v-model="search" placeholder="请输入货位名称搜索" :show-action="true" @custom="loadData" @search="loadData"></u-search>
		</view>
		<u-empty
			style="margin-top: 50%;"
			v-if="!fhList.length"
			text='暂无数据!'
			icon="http://cdn.uviewui.com/uview/empty/data.png"
		>
		</u-empty>
		<view class="scroll-list" croll-y="true" style="width: 100%;padding: 10px;">
			<u-radio-group v-model="value" style="width: 100%;">
				<view v-for="(item, index) in fhList" :key="index" @click="addData(item,index)" style="width: 100%;border: 1px solid #eee;margin-bottom: 10px;border-radius: 5px;background-color: #fff;overflow: hidden;">
					<view class="" >
						<view class="cu-form-group" style="position: relative;">
							<view
								style=" display: inline-block;padding: 5px;background: #3E97B0;color: #fff;min-width: 40px;text-align: center;font-style: italic;font-weight: bold">
								{{ index + 1 }}
							</view>
							<u-radio class="rights" :name="index"></u-radio>
						</view>
						<view class="cu-form-group">
							<view class="title">批次号：</view>
							<view style="flex: 1;"> {{ item.cbatch|| ""  }}
							</view>
						</view>
						<view class="cu-form-group">
							<view class="title">货位编码：</view>
							<view style="flex: 1;"> {{ item.cposCode|| ""  }}
							</view>
						</view>
						<view class="cu-form-group">
							<view class="title">货位名称：</view>
							<view style="flex: 1;"> {{ item.cposName|| ""  }}
							</view>
						</view>
						<view class="cu-form-group">
							<view class="title">数量：</view>
							<view style="flex: 1;"> {{ item.iquantity|| ""  }}
							</view>
						</view>
					</view>
					<!-- <view style="border-bottom: 2px solid #FFFFFF;"></view> -->
				</view>
			</u-radio-group>
			<view class="floatright">
				<u-button type="primary" @click="toAdd">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: null,
				search: "",
				fhList: [],
				radioValue:{},
				query: {
					pageNo: 1,
					pageSize: 999,
				},
				index:0,
			}
		},
		onLoad(params) {
			this.index = params.index
			this.query.cwhCode=params.cwhCode
			this.query.cinvCode=params.cinvCode
			this.query.autoid=params.autoid
			this.loadData()
		},
		methods: {
			loadData() {
				this.query.cposName = this.search
				this.fhList = [];
				this.$u.api.mffh.invPositionSumListData(this.query).then(res => {
					this.fhList = res.list;
				});
			},
			addData(item,index) {
				this.value = index
				this.radioValue = item
			},
			toAdd() {
				if (this.radioValue.cposName != undefined) {
					uni.$emit('hwObjs', {...this.radioValue,index:this.index});
					uni.navigateBack({
						delta: 1,
					})
				} else {
					this.$refs.jsError.showError('',"请选择至少一条数据！",'error');
					return;
				}
			},
		}
	}
</script>

<style>
	.trclass {
		text-align: center;
		padding: 5px 3px;
		border-bottom: 1px solid rgb(228, 231, 237);
		border-right: 1px solid rgb(228, 231, 237);
		flex-direction: column;
		flex: 1;
		justify-content: center;
		font-size: 14px;
		color: #303133;
		font-weight: bold;
		background-color: #f5f6f8;
	}

	.trclass {
		height: 52px;
	}

	.tdclass {
		padding: 5px 3px;
		border-bottom: 1px solid rgb(228, 231, 237);
		border-right: 1px solid rgb(228, 231, 237);
		flex-direction: column;
		flex: 1;
		justify-content: center;
		font-size: 14px;
		color: #505256;
		align-self: stretch;
		box-sizing: border-box;
		height: 100%;
	}

	.box .item {
		margin: 0 0px 0px;
	}

	.tui-line-cell {
		width: 100%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.tui-title {
		line-height: 32rpx;
		min-width: 120rpx;
		flex-shrink: 0;
	}

	.tui-input {
		font-size: 32rpx;
		color: #333;
		padding-left: 20rpx;
		flex: 1;
		overflow: visible;
	}

	.footer {
		position: fixed;
		left: 0;
		bottom: 20px;
		width: 100%;

	}

	.floatright {
		position: fixed;
		bottom: 12px;
		right: 12px;
		width: 25%;
		line-height: var(--footer-height);
		background: #ffffff;
		color: #ffffff;
	}

	.add {
		position: absolute;
		right: 130rpx;
		top: 0;
		margin-right: 0;
	}

	.upload {
		position: absolute;
		right: 65rpx;
		top: 0;
		margin-right: 0;
	}

	.rights {
		position: absolute;
		/* display: inline-block; */
		right: 0;
		top: 15px;
		margin-right: 0;
		/* width: 100%; */

	}
	.title {
		width: 220rpx;
	}
</style>
